package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author stone
 * @date 2022/08/02 11:37
 */
public class CustomBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization:" + beanName);
        // 如果想要对LifeCycleBean里的username做处理
        if (bean instanceof LifecycleBean) {
            ((LifecycleBean)bean).setUsername("远志");
        }
        // 如果想要对DataSource里的password做处理
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization:" + beanName);
        return bean;
    }
}
